package com.zhiwang.planet.util

import androidx.recyclerview.widget.DiffUtil

class DiffCallBack<T> constructor(var oldList: List<T>?, var newList: List<T>?) : DiffUtil.Callback() {

    override fun areItemsTheSame(oldItemPostion: Int, newItemPosition: Int): Boolean {
        return oldList!![oldItemPostion]!! == newList!![newItemPosition]
    }

    override fun getOldListSize(): Int {
        return if (oldList == null) 0 else oldList!!.size
    }

    override fun getNewListSize(): Int {
        return if (newList == null) 0 else newList!!.size
    }

    //暂时没有内容的比较，都只是简单的展示静态item，不涉及item的状态变化
    override fun areContentsTheSame(p0: Int, p1: Int): Boolean {
        return true
    }
}

class SimpleDiffCallBack<T> : DiffUtil.ItemCallback<T>() {
    override fun areItemsTheSame(oldItem: T, newItem: T): Boolean {
        return oldItem?.equals(newItem) != false
    }

    override fun areContentsTheSame(oldItem: T, newItem: T): Boolean {

        return areItemsTheSame(oldItem, newItem)
    }


}